#include  "drv_RTI.h"
#include "system.h"

volatile UINT8 u8_rtctimer = 0;
volatile UINT8 u8_rtctimer_task1m_flag=0;
extern void UdsAppl_Handler1ms(void);
//UINT32 u32_random_value = 0;
 void drv_RTIInit(UINT8 RTI_period_U16)
{
    CPMUAPICTL_APIFE = 0U;      /* API Disabled */
    CPMUAPICTL_APIE  = 0U;      /* Disabled interrupt */
            
    CPMUINT_RTIE = 0U;          /* disable rti interrupt */ 

    CPMURTI_RTDEC = 1U;         /* decimal based divider value */
    CPMURTI_RTR = RTI_period_U16;/* 1MHz/RTR[6:0]��RTR[6:0]*1us */
    

    CPMUFLG_RTIF = 1U;          /* clear the flag of rti */
     
    CPMUINT_RTIE = 1U;          /* enable rti interrupt */ 
}

/*****************************************************************************/
/**
* Function Name: interrupt void isr_RunRTI(void)   
* Description:   Real Time Interrupt.It is disable in stop mode.
*                IRCCLK(IRC1M)-internal reference clock.a factory trim.
*
* Param:   none
* Return:  none
* Author:  
******************************************************************************/
#pragma CODE_SEG __NEAR_SEG NON_BANKED

__interrupt void isr_RunRTI(void)/* 1ms timer interrupt */   
{          
    /* Real Time Interrupt Flag */
    CPMUFLG_RTIF = 1;
    u8_rtctimer_task1m_flag = TRUE;
//    u32_random_value++;
	u8_rtctimer++;  	
    UdsAppl_Handler1ms();/* run mode */ 	
}
#pragma CODE_SEG DEFAULT 